package com.xique.door.controller;

import java.util.List;

import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.web.page.TableDataInfo;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.door.bean.domain.CardDevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.xique.door.service.IDCardDeviceService;

/**
 * deviceController
 *
 * @author caogq
 * @date 2022-02-26
 */
@Controller
@RequestMapping("/door/cardDevice")
public class DCardDeviceController extends BaseController {
    private String prefix = "oms/device";

    @Autowired
    private IDCardDeviceService dCardDeviceService;

    @PreAuthorize(hasPermi = "oms:device:view")
    @GetMapping()
    public String device() {
        return prefix + "/device";
    }

    /**
     * 查询device列表
     */
    @PreAuthorize(hasPermi = "oms:device:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CardDevice cardDevice) {
        startPage();
        List<CardDevice> list = dCardDeviceService.selectDCardDeviceList(cardDevice);
        return getDataTable(list);
    }


    /**
     * 新增device
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存device
     */
    @PreAuthorize(hasPermi = "oms:device:add")
    @Log(title = "device", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CardDevice cardDevice) {
        return toAjax(dCardDeviceService.insertDCardDevice(cardDevice));
    }

    /**
     * 修改device
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        CardDevice cardDevice = dCardDeviceService.selectDCardDeviceById(id);
        mmap.put("dCardDevice", cardDevice);
        return prefix + "/edit";
    }

    /**
     * 修改保存device
     */
    @PreAuthorize(hasPermi = "oms:device:edit")
    @Log(title = "device", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CardDevice cardDevice) {
        return toAjax(dCardDeviceService.updateDCardDevice(cardDevice));
    }

    /**
     * 删除device
     */
    @PreAuthorize(hasPermi = "oms:device:remove")
    @Log(title = "device", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(dCardDeviceService.deleteDCardDeviceByIds(ids));
    }
}
